//
//  AnalyseViewController.m
//  Shine
//
//  Created by 王斌 on 16/3/9.
//  Copyright © 2016年 王斌. All rights reserved.
//

#import "AnalyseViewController.h"
#import "TitieCollectionViewCell.h"//标题
#import "StepsCollectionViewCell.h"//步数
#import "CaloriesCollectionViewCell.h"//kalul
#import "WeightCollectionViewCell.h"//体重
#import "AdvancedCollectionViewCell.h"//高级




#define HEIGHT self.view.frame.size.height
#define WIDTH self.view.frame.size.width
//屏幕宽
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
//屏幕高
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

@interface AnalyseViewController ()<UICollectionViewDataSource , UICollectionViewDelegate>

@property(nonatomic , retain)UICollectionView *collectionView;
@property(nonatomic , retain)UICollectionView *titleCollectionView;
//标题数组
@property(nonatomic , retain)NSMutableArray *titleArr;



@end

@implementation AnalyseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createView];
}

- (void)createView
{
    //滚动标题
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(90, 30);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 5, 0, 5);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 5;
    
    self.titleCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40) collectionViewLayout:flowLayout];
    self.titleCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.titleCollectionView];
    self.titleCollectionView.delegate = self;
    self.titleCollectionView.dataSource = self;
    [self.titleCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"titleCollectionViewCell"];
    
    self.titleCollectionView.showsHorizontalScrollIndicator = NO;
    self.titleCollectionView.pagingEnabled = YES;
    self.titleCollectionView.bounces = NO;
    
    
    //页面
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    //item尺寸一个屏幕
    flow.itemSize = self.view.frame.size;
    //行间距,列间距
    flow.minimumLineSpacing = 0;
    flow.minimumInteritemSpacing = 0;
    //与屏幕四周距离
    flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    //滚动方向,横向
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //创建collecView
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 40,SCREEN_WIDTH , SCREEN_HEIGHT) collectionViewLayout:flow];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    //以页滑动
    self.collectionView.pagingEnabled = YES;
    //取消弹回效果
    self.collectionView.bounces = NO;
    [self.view addSubview:self.collectionView];
    
    //注册
    [self.titleCollectionView registerClass:[TitieCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [self.collectionView registerClass:[StepsCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [self.collectionView registerClass:[CaloriesCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [self.collectionView registerClass:[WeightCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [self.collectionView registerClass:[AdvancedCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    self.titleArr = [NSMutableArray arrayWithObject:@[@"步数",@"大卡",@"体重",@"高级",]];
}

#pragma mark collectionView协议
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.titleArr.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.titleCollectionView) {
        TitieCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
        return cell;
    }else{
        if (indexPath.row == 0) {
            //步数
            StepsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
            return cell;
        }else if (indexPath.row == 1){
            //卡路里
            CaloriesCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
            return cell;
        }else if (indexPath.row == 2){
            //体重
            WeightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
            return cell;
        }else{
            //高级
            AdvancedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
            return cell;
        }
    }

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
